﻿using System;
using System.Data;
using System.Collections.Generic;
using OnlineTestCOMMON;
using OnlineTestDAL;
using OnlineTestModel;
namespace OnlineTestBLL
{
	/// <summary>
	/// paperquestions
	/// </summary>
	public partial class PaperQuestionsBLL
	{
        private readonly PaperQuestionsDAL dal = new PaperQuestionsDAL();
		public PaperQuestionsBLL()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int id)
		{
			return dal.Exists(id);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(PaperQuestions model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
        public bool Update(PaperQuestions model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int id)
		{
			
			return dal.Delete(id);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			return dal.DeleteList(idlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
        public PaperQuestions GetModel(int id)
		{
			
			return dal.GetModel(id);
		}

        #region 得到一个对象实体，从缓存中

        ///// <summary>
	    ///// 得到一个对象实体，从缓存中
	    ///// </summary>
	    //public PaperQuestions GetModelByCache(int id)
	    //{

	    //    string CacheKey = "paperquestionsModel-" + id;
	    //    object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
	    //    if (objModel == null)
	    //    {
	    //        try
	    //        {
	    //            objModel = dal.GetModel(id);
	    //            if (objModel != null)
	    //            {
	    //                int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
	    //                Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
	    //            }
	    //        }
	    //        catch{}
	    //    }
	    //    return (PaperQuestions)objModel;
	    //}

	    #endregion


		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int top,string strWhere,string filedOrder)
		{
			return dal.GetList(top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<PaperQuestions> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<PaperQuestions> DataTableToList(DataTable dt)
		{
			List<PaperQuestions> modelList = new List<PaperQuestions>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				PaperQuestions model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new PaperQuestions();
					if(dt.Rows[n]["id"]!=null && dt.Rows[n]["id"].ToString()!="")
					{
						model.Id=int.Parse(dt.Rows[n]["id"].ToString());
					}
					if(dt.Rows[n]["paperid"]!=null && dt.Rows[n]["paperid"].ToString()!="")
					{
						model.PaperId=int.Parse(dt.Rows[n]["paperid"].ToString());
					}
					if(dt.Rows[n]["questionid"]!=null && dt.Rows[n]["questionid"].ToString()!="")
					{
						model.QuestionId=int.Parse(dt.Rows[n]["questionid"].ToString());
					}
					if(dt.Rows[n]["bigquestion"]!=null && dt.Rows[n]["bigquestion"].ToString()!="")
					{
						model.BigQuestion=int.Parse(dt.Rows[n]["bigquestion"].ToString());
					}
					if(dt.Rows[n]["smallquestion"]!=null && dt.Rows[n]["smallquestion"].ToString()!="")
					{
						model.SmallQuestion=int.Parse(dt.Rows[n]["smallquestion"].ToString());
					}
					if(dt.Rows[n]["score"]!=null && dt.Rows[n]["score"].ToString()!="")
					{
						model.Score=int.Parse(dt.Rows[n]["score"].ToString());
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

